﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Http;
using AttributeRouting;
using AttributeRouting.Web.Http;
using AutoFacWrapper;
using ZLWeb.WebApiEntity;
using ZLWeb.WebApiEntity.EasyUse;
using ZLWeb.WebApiRepository.InterFace;

namespace ZLWeb.WebApiControllers.Controllers
{
    /// <summary>
    /// 方便用
    /// </summary>
   [RoutePrefix("Api/EasyUse")]
    public class EasyUseController :  ApiController
    {
        [GET("GetNo")]
        public AccInfo GetNo(string openid)
        {
            var paymentRepo = ClassFactory.GetInstance<IPaymentRepository>();
            return paymentRepo.GetAccInfo(openid, 2, 1, 0);
        }

        [GET("GetAllAccInfo")]
        [System.Web.Http.HttpGet]
        public AccInfoResponse GetAllAccInfo(string openid)
        {
            var paymentRepo = ClassFactory.GetInstance<IPaymentRepository>();
            return paymentRepo.GetallAccInfo(openid, 2, 1, 0);
        }

        [GET("SimpleRegesiter")]
        [System.Web.Http.HttpGet]
        public ResponseResultInfo SimpleRegesiter(string openid, string phone)
        {
            var regesiterRepo = ClassFactory.GetInstance<IRegesiterRepository>();
            ywInfo info = new ywInfo() { oprcardno = openid, oprctype = 2, oprcellphone = phone };
            string oprpj = Guid.NewGuid().ToString().Substring(0, 5);
            dpno sd = new dpno();
            sd.pno = Guid.NewGuid().ToString().Substring(0, 5);
            sd.pnopwd = Guid.NewGuid().ToString().Substring(0, 5);
            regesiterRepo.SimpleRegesiter(info, oprpj, sd);
            return new ResponseResultInfo();
        }

        [GET("ChargeInfo")]
        [System.Web.Http.HttpGet]
        public ZzinfocsResponse GetChargeInfo()
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            IEnumerable<Zzinfocs> items= chargeRepo.GetChargeInfo("10001", 1);
            return new ZzinfocsResponse() {Zzinfocss = items};
        }

        [GET("GetProfileAccinfo")]
        public ProfileAccinfoResponse GetProfileAccinfoResponse(string openid)
        {
            var profileAccin = ClassFactory.GetInstance<IProfileAccinfoRepository>();
            return profileAccin.GetProfileAccInfo(openid, 2, 1, 0);
        }

        [POST("UpdateProfile")]
        public ProfileAccinfoResponse UpdateProfileAccInfoResponse(ProfileAccinfo tem)
        {
            var profileAccin = ClassFactory.GetInstance<IProfileAccinfoRepository>();
            return profileAccin.UpdateProfileAccInfo(tem, tem.dycardno, 5);
        }

        [POST("PreCharge")]
        public AccCzResponse PreCharge(ThrywInfo ywInfo)
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            return chargeRepo.PreCharge(ywInfo,ywInfo.cardno, ywInfo.ctype);
        }

        [POST("ChargeNewSave")]
        public Thrpaylog ChargeNewSave(Thrpaylog log)
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            return chargeRepo.ChargeNewSave(log, log.payway);
        }

        [POST("ChargeModifySave")]
        public Thrpaylog ChargeModifySave(Thrpaylog log)
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            return chargeRepo.ChargeModifySave(log, log.payway, log.paysno);
        }

        [POST("ChargeResultQuery")]
        public Result ChargeResultQuery(QueryParam param)
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            return chargeRepo.ChargeResultQuery(param.payway, param.pno, param.pnopwd);
        }

        [GET("ChargeCancel")]
        [System.Web.Http.HttpGet]
        public ResponseResultInfo ChargeCancel(string pno, string pnopwd)
        {
            var chargeRepo = ClassFactory.GetInstance<IChargeRepository>();
            chargeRepo.ChargeCancel(pno, pnopwd);
            return new ResponseResultInfo();
        }
    }
}
